package com.cloudream.toucheventdemo.viewgroup;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import com.cloudream.toucheventdemo.utils.EventUtils;

/**
 * Created by Administrator on 2019/8/20.
 */

public class EventView extends View {

    public static final String TAG = "EventView";

    public EventView(Context context) {
        super(context);
    }

    public EventView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public EventView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        Log.i(TAG,":: dispatchTouchEvent ::"+ EventUtils.getEvent(event)+"RawY:"+event.getRawY());

        if(event.getAction() == MotionEvent.ACTION_DOWN){
            getParent().requestDisallowInterceptTouchEvent(true);
        }else if(event.getAction() == MotionEvent.ACTION_MOVE){
            if(event.getRawY() > 500){
                getParent().requestDisallowInterceptTouchEvent(false);
            }
        }



        boolean dispatchTouchEvent = super.dispatchTouchEvent(event);
        Log.i(TAG,":: dispatchTouchEvent ::"+ EventUtils.getEvent(event)+"result:"+dispatchTouchEvent);
        return dispatchTouchEvent;
    }

//    @Override
//    public boolean onTouchEvent(MotionEvent event) {
//        Log.i(TAG,":: onTouchEvent ::"+ EventUtils.getEvent(event));
//        return true;
//    }
}
